#include "MatrixKey.h"
#include "Delay.h"
/*
*@brief :扫描矩阵键盘按键键码
*@param :无
*@retval:按下按键的键码值
*/
unsigned char MatrixKey(void)
{
	unsigned char Key_Num = 0;
	P1 = 0XFF;
	P1_3 = 0;
	if (P1_7 == 0){Delay1ms(20);while (P1_7 == 0);Delay1ms(20);Key_Num = 1;}
	if (P1_6 == 0){Delay1ms(20);while (P1_6 == 0);Delay1ms(20);Key_Num = 5;}
	if (P1_5 == 0){Delay1ms(20);while (P1_5 == 0);Delay1ms(20);Key_Num = 9;}
	if (P1_4 == 0){Delay1ms(20);while (P1_4 == 0);Delay1ms(20);Key_Num = 13;}
	P1 = 0XFF;
	P1_2 = 0;
	if (P1_7 == 0){Delay1ms(20);while (P1_7 == 0);Delay1ms(20);Key_Num = 2;}
	if (P1_6 == 0){Delay1ms(20);while (P1_6 == 0);Delay1ms(20);Key_Num = 6;}
	if (P1_5 == 0){Delay1ms(20);while (P1_5 == 0);Delay1ms(20);Key_Num = 10;}
	if (P1_4 == 0){Delay1ms(20);while (P1_4 == 0);Delay1ms(20);Key_Num = 14;}
	P1 = 0XFF;
	P1_1 = 0;
	if (P1_7 == 0){Delay1ms(20);while (P1_7 == 0);Delay1ms(20);Key_Num = 3;}
	if (P1_6 == 0){Delay1ms(20);while (P1_6 == 0);Delay1ms(20);Key_Num = 7;}
	if (P1_5 == 0){Delay1ms(20);while (P1_5 == 0);Delay1ms(20);Key_Num = 11;}
	if (P1_4 == 0){Delay1ms(20);while (P1_4 == 0);Delay1ms(20);Key_Num = 15;}
	P1 = 0XFF;
	P1_0 = 0;
	if (P1_7 == 0){Delay1ms(20);while (P1_7 == 0);Delay1ms(20);Key_Num = 4;}
	if (P1_6 == 0){Delay1ms(20);while (P1_6 == 0);Delay1ms(20);Key_Num = 8;}
	if (P1_5 == 0){Delay1ms(20);while (P1_5 == 0);Delay1ms(20);Key_Num = 12;}
	if (P1_4 == 0){Delay1ms(20);while (P1_4 == 0);Delay1ms(20);Key_Num = 16;}
	return Key_Num;
}